#pragma once
#include <iostream>
#include <vector>
#include <functional>
#include <ctime>
#include <cassert>
#include <sys/types.h>
#include <unistd.h>
using namespace std;

using task_t = function<void()>;

void Download()
{
    cout << "我是一个下载任务, 我的工作id是：" << getpid() << endl;
}

void PrintLog()
{
    cout << "我是一个打印日志任务, 我的工作id是：" << getpid() << endl;
}

void TransferringVideoStreams()
{
    cout << "我是一个传输视频流任务, 我的工作id是：" << getpid() << endl;
}

class Task
{
private:
    const static int download = 0;
    const static int printlog = 1;
    const static int transferringvideostreams = 2;

    static vector<task_t> _task;
public:
    Task()
    {
        _task.push_back(Download);
        _task.push_back(PrintLog);
        _task.push_back(TransferringVideoStreams);

        srand((unsigned)time(nullptr));
    }

    int GetTaskNum()
    {
        return rand() % _task.size();
    }

    task_t GetTask(int n)
    {
        assert(n >= 0 && n < _task.size());
        return _task[n];
    }

    string GetTaskName(int n)
    {
        switch(n)
        {
            case download: 
                return "Download"; 
                break;
            case printlog:
                return "PrintLog";
                break;
            case transferringvideostreams:
                return "TransferringVideoStreams";
                break;
            default:
                return "";
                break;
        }
    }

};

vector<task_t> Task::_task;

Task task;